<?php

global $Application_Maker, $oThis;
if (!class_exists('setInBodyCategorySelectCls')) {

    class setInBodyCategorySelectCls extends Application_Maker_setField {

        public function __construct() {
            $this->fieldtype = "setInBodyCategorySelect";
            $this->hasSaveField = true;
            $this->AbortGlobalSave = false;
        }

        public function getField($oThis, $config, $post, $meta_marker) {
            $this->init($oThis, $config, $post, $meta_marker);
            // print_r($oThis);exit();
            $str = "<div class='c_field_container c_InBodyCategorySelect' data-field_type='setInBodyCategorySelect'
                     data-fwidthCls='" . $config['fwidthCls'] . "'
                     data-field='" . $config['field'] . "'
                     data-value ='" . $config['value'] . "'
                     data-label ='" . $config['label'] . "'
                     data-category='" . $config['field_config']['category'] . "'
                     data-meta_marker='" . $meta_marker . "'></div>";
            return $str; //'test'.$this->meta_marker."**".$this->add_image;
        }

        public function getColumnData($meta, $field, $post_id) {
           // var_dump($field);
            $taxonomies = $field['field_config']['category'];
           // echo $post_id . '++taxonomies ' . $taxonomies;
            //$metao = wp_get_object_terms($post_id, $taxonomies);
            $t=get_term( $meta, $taxonomies );
            //var_dump($t);
            return $t->name;//$metao[0]->name;
        }

        public function saveField($post_id, $key, $meta_marker, $data, $field) {
            //echo $post_id."//".$key."**".$data;
            if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) {
                return $post_id;
            }
            $cat = $field['field_config']['category'];
            $data = intval($data);
            wp_set_object_terms($post_id, array($data), $cat);
            return $data;
        }

    }

}

$oThis->extension_class_instances['setInBodyCategorySelect'] = new setInBodyCategorySelectCls();
?>
